package com.example.no1admin.schedule;

import com.example.no1admin.mapper.PictureMapper;
import com.example.no1admin.pojo.vo.picture.PictureListItemVO;
import com.example.no1admin.repo.impl.PictureRepositoryImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class CacheSchedule {
    @Autowired
    private PictureMapper pictureMapper;

    @Autowired
    private PictureRepositoryImpl pictureRepository;

    @Scheduled(fixedRate = 10 * 60 * 1000)
    public void updateCache() {
        log.debug("执行CacheSchedule.updateCache()方法");
        //删除Redis中的品牌列表
        pictureRepository.deleteList();
        log.debug("从MySQL中读取品牌列表并写入到Redis");
        List<PictureListItemVO> pictureListItemVOS = pictureMapper.list();
        pictureRepository.putList(pictureListItemVOS);
    }
}
